package com.hadoop.mr.score_statistics;

import java.io.IOException;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class ScoreReduce extends Reducer<Text, Student, Text, Text> {

	@Override
	protected void reduce(Text key, Iterable<Student> valuse, Context context) throws IOException, InterruptedException {
		int chineseSum = 0;
		int englishSum = 0;
		int mathSum = 0;
		for (Student stu : valuse) {
			System.out.println(stu.getSubject());
			switch (stu.getSubject()) {
			case "english":
				englishSum = englishSum + stu.getScore();
				System.out.println("!!!!"+ englishSum);
				break;
			case "chinese":
				chineseSum = chineseSum + stu.getScore();
				break;
			case "math":
				mathSum = mathSum + stu.getScore();
				break;
			default:
				break;
			}
		}
		context.write(key, new Text("{ name = "+ key +" chinese = "+chineseSum+" english = "+englishSum+"  mathSum = "+mathSum+"}"));
	}

}
